home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / realse1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-10-17  |  8.1 KB  |  263 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2910
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   3030
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2910
  10.    ScaleWidth      =   3030
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox txtBody 
  13.       Height          =   1215
  14.       Left            =   0
  15.       MultiLine       =   -1  'True
  16.       ScrollBars      =   2  'Vertical
  17.       TabIndex        =   11
  18.       Top             =   1200
  19.       Width           =   3015
  20.    End
  21.    Begin VB.TextBox txtSubject 
  22.       Height          =   285
  23.       Left            =   0
  24.       TabIndex        =   10
  25.       Text            =   "Subject"
  26.       Top             =   960
  27.       Width           =   3015
  28.    End
  29.    Begin VB.TextBox txtEmail 
  30.       Height          =   285
  31.       Left            =   360
  32.       TabIndex        =   8
  33.       Text            =   "email_address of sender"
  34.       Top             =   480
  35.       Width           =   2655
  36.    End
  37.    Begin VB.TextBox txtSender 
  38.       Height          =   285
  39.       Left            =   360
  40.       TabIndex        =   6
  41.       Text            =   "nickname of sender"
  42.       Top             =   240
  43.       Width           =   2655
  44.    End
  45.    Begin VB.TextBox txtICQNUM 
  46.       Height          =   285
  47.       Left            =   360
  48.       TabIndex        =   4
  49.       Text            =   "ICQ_NUMBER"
  50.       Top             =   0
  51.       Width           =   2655
  52.    End
  53.    Begin VB.CommandButton Command2 
  54.       Caption         =   "Exit"
  55.       Height          =   375
  56.       Left            =   1560
  57.       TabIndex        =   3
  58.       Top             =   2520
  59.       Width           =   1455
  60.    End
  61.    Begin VB.TextBox DataArrival 
  62.       Height          =   285
  63.       Left            =   0
  64.       TabIndex        =   2
  65.       Top             =   3120
  66.       Width           =   1095
  67.    End
  68.    Begin VB.CommandButton Command1 
  69.       Caption         =   "Send Message"
  70.       Height          =   375
  71.       Left            =   0
  72.       TabIndex        =   1
  73.       Top             =   2520
  74.       Width           =   1455
  75.    End
  76.    Begin VB.TextBox Text1 
  77.       Height          =   1215
  78.       Left            =   0
  79.       MultiLine       =   -1  'True
  80.       ScrollBars      =   2  'Vertical
  81.       TabIndex        =   0
  82.       Top             =   3480
  83.       Width           =   3015
  84.    End
  85.    Begin VB.Label Label3 
  86.       Caption         =   "email:"
  87.       Height          =   255
  88.       Left            =   0
  89.       TabIndex        =   9
  90.       Top             =   480
  91.       Width           =   375
  92.    End
  93.    Begin VB.Label Label2 
  94.       Caption         =   "from:"
  95.       Height          =   255
  96.       Left            =   0
  97.       TabIndex        =   7
  98.       Top             =   240
  99.       Width           =   375
  100.    End
  101.    Begin VB.Label Label1 
  102.       Caption         =   "to:"
  103.       Height          =   255
  104.       Left            =   0
  105.       TabIndex        =   5
  106.       Top             =   0
  107.       Width           =   375
  108.    End
  109. Attribute VB_Name = "Form1"
  110. Attribute VB_GlobalNameSpace = False
  111. Attribute VB_Creatable = False
  112. Attribute VB_PredeclaredId = True
  113. Attribute VB_Exposed = False
  114. Private bTrans As Boolean
  115. Private Sock As Integer
  116. Private RC As Integer
  117. Private Bytes As Integer
  118. Private Const httpserver As String = "wwp.icq.com"
  119. Public remotefile As String
  120. 'This is for the WaitforResponse Routine
  121. Private Declare Function timeGetTime Lib "winmm.dll" () As Long
  122. Private Function ReplaceText(object$, RepWhat$, RepWit$) As String
  123. Dim bwah, bwh, temp1, temp2
  124. On Error Resume Next
  125. bwah = object$
  126.     bwh = InStr(bwah, RepWhat$)
  127.     If bwh <> 0 Then
  128.  temp1 = Left$(bwah, bwh - 1)
  129.  temp2 = Right$(bwah, Len(bwah) - (bwh))
  130.  bwah = temp1 & RepWit$ & temp2
  131.  GoTo la
  132.     End If
  133. NulDetect:
  134. ReplaceText = bwah
  135. End Function
  136. Private Sub Command1_Click()
  137. 'build remote file string so to speak watch debug window
  138. 'to see what it ends up looking like if you are interested
  139. remotefile = "/scripts/WWPMsg.dll?from=" & txtSender.Text
  140. remotefile = remotefile & "&fromemail=" & txtEmail.Text
  141. remotefile = remotefile & "&subject=" & ReplaceText(txtSubject.Text & "", Chr$(32), "+")
  142. remotefile = remotefile & "&body=" & ReplaceText(txtBody.Text & "", Chr$(32), "+")
  143. remotefile = remotefile & "&to=" & Val(txtICQNUM.Text) & "&"
  144. Debug.Print remotefile & ""
  145. Dim StartupData As WSADataType
  146. Dim SocketBuffer As sockaddr
  147. Dim IpAddr As Long
  148. Dim StrWebPage As String, StrCommand As String
  149. 'Initialize the socket
  150. RC = WSAStartup(&H101, StartupData)
  151. RC = WSAStartup(&H101, StartupData)
  152. Sock = socket(AF_INET, SOCK_STREAM, 0)
  153. If Sock = SOCKET_ERROR Then
  154.     Debug.Print "Cannot Create Socket."
  155.     Exit Sub
  156. End If
  157. 'Checks if the Hostname exists
  158. If RC = SOCKET_ERROR Then Exit Sub
  159. IpAddr = GetHostByNameAlias(httpserver)
  160. If IpAddr = -1 Then
  161.     Debug.Print "Unknown Host: " + httpserver
  162.     Exit Sub
  163. End If
  164. 'This part is responsible for the connection
  165. 'as well as setting port
  166. SocketBuffer.sin_family = AF_INET
  167. SocketBuffer.sin_port = htons(80)
  168. SocketBuffer.sin_addr = IpAddr
  169. SocketBuffer.sin_zero = String$(8, 0)
  170. RC = connect(Sock, SocketBuffer, Len(SocketBuffer))
  171. 'If an error occured close the connection and
  172. 'send an error message to the text window
  173. If RC = SOCKET_ERROR Then
  174.         Debug.Print "Cannot Connect to " + httpserver + _
  175.                             Chr$(13) + Chr$(10) + _
  176.                             GetWSAErrorString(WSAGetLastError())
  177.         closesocket Sock
  178.         RC = WSACleanup()
  179.         Exit Sub
  180. End If
  181. 'Select Receive Window (textbox named DataArrival
  182. RC = WSAAsyncSelect(Sock, DataArrival.hWnd, _
  183.                         ByVal &H202, ByVal FD_READ Or FD_CLOSE)
  184.     If RC = SOCKET_ERROR Then
  185.         Debug.Print "Cannot Process Asynchronously."
  186.         closesocket Sock
  187.         RC = WSACleanup()
  188.         Exit Sub
  189.     End If
  190. bTrans = True
  191. DataArrival = ""
  192.     'build the command to send to http server
  193.   StrWebPage = remotefile
  194.   StrCommand = "GET " + StrWebPage & vbCrLf '+ " HTTP/1.0" + vbCrLf
  195.   StrCommand = StrCommand + "Accept: */*" + vbCrLf
  196.   'StrCommand = StrCommand + "Accept: text/html" + vbCrLf
  197.   'StrCommand = StrCommand + vbCrLf
  198.   'send command to server
  199.   WinsockSendData StrCommand & ""
  200. Call WaitForResponse
  201. End Sub
  202. Private Sub WaitForResponse()
  203. Dim Start As Long
  204. Dim Tmr As Long
  205. 'Works with an Api Declaration because it's more precious
  206. Start = timeGetTime
  207. While Bytes > 0
  208.     Tmr = timeGetTime - Start
  209.     DoEvents ' Let System keep checking for incoming response
  210.         
  211.     'Wait 50 seconds for response
  212.     If Tmr > 50000 Then
  213.         MsgBox "SMTP service error, timed out while waiting for response", 64, "Error!"
  214.         End
  215.     End If
  216. End Sub
  217. Private Sub Command2_Click()
  218. On Error Resume Next
  219.     closesocket Sock
  220.     RC = WSACleanup()
  221.     End
  222. End Sub
  223. Private Sub DataArrival_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  224. Dim MsgBuffer As String * 2048
  225. On Error Resume Next
  226.     If Sock > 0 Then
  227.         'Receive up to 2048 chars
  228.         Bytes = recv(Sock, ByVal MsgBuffer, 2048, 0)
  229.         
  230.         If Bytes > 0 Then
  231.             
  232.                 
  233.             If bTrans Then
  234.             Text1.Text = Text1.Text & MsgBuffer
  235.         ElseIf WSAGetLastError() <> WSAEWOULDBLOCK Then
  236.             closesocket (Sock)
  237.             RC = WSACleanup()
  238.             Sock = 0
  239.         End If
  240.     End If
  241. End If
  242. Refresh
  243. End Sub
  244. Private Sub WinsockSendData(DatatoSend As String)
  245. Dim RC As Integer
  246. Dim MsgBuffer As String * 2048
  247. MsgBuffer = DatatoSend
  248. RC = send(Sock, ByVal MsgBuffer, Len(DatatoSend), 0)
  249. 'If an error occurs send an error message and
  250. 'reset the winsock
  251. If RC = SOCKET_ERROR Then
  252.     Debug.Print "Cannot Send Request." + _
  253.                             Chr$(13) + Chr$(10) + _
  254.                             Str$(WSAGetLastError()) + _
  255.                             GetWSAErrorString(WSAGetLastError())
  256.     closesocket Sock
  257.     RC = WSACleanup()
  258.     Exit Sub
  259. End If
  260. End Sub
  261. Private Sub Form_Load()
  262. End Sub
  263.